﻿@using System.Collections.Generic
@using Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security
@using GlobalResources
@using Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Navigation

@model List<Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Navigation.NavigationMenuItem>
<nav class="navigation">
    @foreach (var navigationMenuItem in Model)
    {
        if (navigationMenuItem.Selected)
        {
            <a class="navigation__link @navigationMenuItem.Class">@navigationMenuItem.Text</a>
        }
        else
        {
            var multipleClasses = "navigation__link " + navigationMenuItem.Class;
            @Html.ActionLink(navigationMenuItem.Text, navigationMenuItem.Action, navigationMenuItem.Controller, null, new { @class = multipleClasses })
        }
    }

    @if (PermsChecker.HasPermission(Permission.AddDevices))
    {
        <a class="navigation__link navigation__link--add_device" href="@Url.Action("AddDevice", "Device")">@Strings.AddDevice</a>
    }
</nav>

@foreach (var navigationMenuItem in Model.Where(navigationMenuItem => navigationMenuItem.Selected && navigationMenuItem.Children != null))
{
    <nav class="navigation">
        @foreach (var childNavigationItem in navigationMenuItem.Children)
        {
            if (childNavigationItem.Selected)
            {
                <a class="@childNavigationItem.Class">@childNavigationItem.Text</a>
            }
            else
            {
                @Html.ActionLink(childNavigationItem.Text, childNavigationItem.Action, childNavigationItem.Controller, null, new { @class = childNavigationItem.Class })
            }
        }
    </nav>
}
